package rz.rmi;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;

public class Client {
	private static final String host = "127.0.0.1";  
    private static final int port = 8800;  
	/**
	 * @param args
	 * @author ddh
	 */
	public static void main(String[] args) {
		System.setProperty("java.security.policy", "src/rmi/client.policy");//权限控制  
		System.setSecurityManager(new RMISecurityManager());  
		String url = "rmi://"+host+":"+port+"/";  
		
		try {
			
			MyRemote remote =  (MyRemote)Naming.lookup(url + "/MyRemote");
			System.out.println(remote.sayHello("Java"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		}
		try {
			
			MyRemote remote =  (MyRemote)Naming.lookup("rmi://localhost:"+ port +"/MyRemote");
			System.out.println(remote);
			System.out.println(remote.sayHello("Java"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		}
		try {
	        
			MyRemote remote =  (MyRemote)Naming.lookup("rmi://192.168.0.224:"+ port +"/MyRemote");
			System.out.println(remote);
			System.out.println(remote.sayHello("Java"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		}
	}

}
